package com.jhws.business.face.service;

import com.jhws.business.comm.bo.TblBuildingDimBo;
import com.jhws.business.comm.bo.TblCommDimBo;
import com.jhws.business.comm.service.ITblBuildingDimService;
import com.jhws.business.comm.service.ITblCommDimService;
import com.jhws.business.face.bo.FaceDataUpdate;
import com.jhws.business.face.bo.FaceInfo;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FaceAsyncService {

    @Resource
    private ITblBuildingDimService buildingDimService;
    @Resource
    private ITblCommDimService commDimService;
    @Resource
    private DataUpdateService dataUpdateService;

    /**
     * 推送通知修改
     *
     * @param time
     * @param commCode
     * @param faceInfos
     * @throws Exception
     */
    @Async
    public void push(long time, String commCode, List<FaceInfo> faceInfos) throws Exception {
        Thread.sleep(2000);
        //推送门口机
        for (FaceInfo f : faceInfos) {
            List<TblBuildingDimBo> list = buildingDimService.findTblBuildingDimByWhere(
                    "where comm_code = '" + f.getCommCode() +
                            "' and area_name='" + Integer.valueOf(f.getBuilding()) +
                            "' and building_name='" + Integer.valueOf(f.getUnit()) + "'");
            for (TblBuildingDimBo buildingDimBo : list) {
                for (int i = 1; i < buildingDimBo.getDevNumber() + 1; i++) {
                    String label = f.getCommCode() + f.getBuilding() + f.getUnit() + "000" + i;
                    dataUpdateService.pushAndUpdate(time, FaceDataUpdate.FACE, label, true, false, "", "");
                }
            }
        }
        //围墙机推送
        TblCommDimBo commDimBo = commDimService.findTblCommDimByCommCode(commCode);
        int gateDevNum = commDimBo.getGateDevNum();
        if (gateDevNum > 0) {
            for (int i = 0; i < gateDevNum; i++) {
                String sipNum = commCode + "0000000" + (char) ('a' + i);
                dataUpdateService.pushAndUpdate(time, FaceDataUpdate.FACE, sipNum, true, false, "", "");
            }
        }
    }
}
